home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / vidhandl / plus.cpp < prev    next >
C/C++ Source or Header  |  1999-02-03  |  9KB  |  305 lines

  1. /*PLUS.CPP IS A EXAMPLE OF VIDEO HANDLING FUNCTIONS                        */
  2. /*PLUS.CPP illustrates the possibility to create enhanced versions of       */
  3. /*VIDEO HANDLING FUNCTIONS.                                                */
  4. /*To compile with command line compiler, type TCC -O -Z PLUS.CPP           */
  5. /*To compile this you will need first to install VIDEO HANDLING FUNCTIONS  */
  6. /*                                                                         */
  7. /* FREEWARE/PUBLIC DOMAIN                                                  */
  8. /*Copyright (c) by Márcio Afonso Arimura Fialho                            */
  9. /*http://pessoal.iconet.com.br/jlfialho                                    */
  10. /*E-mail:jlfialho@iconet.com.br                                            */
  11. /*Alternate E-mail: jlfialho@yahoo.com (use only if the above doesn't work */
  12.  
  13. /*WARNING: THIS EXAMPLE REQUIRES AT LEAST AN EGA VIDEO ADAPTER             */
  14.  
  15. /*WARNING: When running this program under a MS-Windows MS-DOS prompt, be  */
  16. /* sure that the MS-DOS prompt is in full screen mode, because some        */
  17. /* functions used by this example aren't effective in a MS-DOS window      */
  18.  
  19. /*This example is based on VIDEOHLP.TXT Example 2. Notice the resemblance  */
  20.  
  21. /*For further information, read \EXAMPLES\README.TXT                       */
  22.  
  23. #include <crt.h>
  24. #include <conio.h>
  25.  
  26. #include "linedrw2.cpp" //font used by enhanced mkline functions
  27.  
  28. #include "xmkline.c" //enhanced versions of mkline and mkline_aux
  29.  
  30. //crtframe, mkline, and macros examples.
  31. //This example contains many sub-examples. Perhaps it is interesting
  32. //to separate them.
  33.  
  34. #define VGA 9
  35. #define EGA 3
  36.  
  37. #define VIDEOTYPE VGA  //if your video adapter is EGA, redefine this.
  38.  
  39. void pause ()
  40.  {
  41.     asm push ax;
  42.     asm mov ah,0x08;
  43.     asm int 0x21;
  44.     asm pop ax;
  45.  }
  46.  
  47. void blkspec (int blk) //enables the display of two character fonts
  48.  {
  49.     asm push ax;
  50.     asm push bx;
  51.     _BL=blk;
  52.     _AX=0x1103;
  53.     asm int 0x10;
  54.     asm pop bx;
  55.     asm pop ax;
  56.  }
  57.  
  58. void initxmkline() //selects mkline font and updates crtframe_mat
  59.  {
  60.     char *p;
  61.     setcrtmode (3);
  62.     changechar_blk=1;
  63.     changechar(linedrw2_font,0,0x100);
  64.     blkspec(4); //light foreground colored text will be written with linedrw2_font
  65.                     //dark foregound colored text will be written with standard font
  66.  
  67.     //it's not required to create a enhanced version of crtframe to display
  68.     //characters with triple or quadruple outline, all that is needed is to
  69.     //change crtframe_mat characters.
  70.     p=(char *)crtframe_mat+16;
  71.  
  72.   //triple outline
  73.     *p='π'; p++;
  74.     *p='è'; p++;
  75.     *p='Σ'; p++;
  76.     *p='Ñ'; p++;
  77.     *p='τ'; p++;
  78.     *p='è'; p++;
  79.     *p='µ'; p++;
  80.     *p='Ñ'; p++;
  81.  
  82.   //quadruple outline
  83.     *p='b'; p++;
  84.     *p=3;   p++;
  85.     *p='c'; p++;
  86.     *p='('; p++;
  87.     *p='f'; p++;
  88.     *p=3;   p++;
  89.     *p='e'; p++;
  90.     *p='('; p++;
  91.  
  92. #if VIDEOTYPE==VGA
  93.     setchrboxwidth (1);
  94. #endif
  95.  }
  96.  
  97.     //crtframe extended macros
  98. #define moldurat(xi,yi,xf,yf,color)\
  99.     crtframe(xi,yi,xf,yf,color,2)    //draws a text frame with triple outline
  100. #define molduraq(xi,yi,xf,yf,color)\
  101.     crtframe(xi,yi,xf,yf,color,3)    //draws a text frame with quadruple outline
  102.  
  103.     //crtframew extended macros
  104. #define molduratw(color)\
  105.     crtframew(color,2)
  106. #define molduraqw(color)\
  107.     crtframew(color,3)
  108.  
  109.     //linha... macros will be redefined, therefore they need to be undefined
  110. #undef linha_hor
  111. #undef linha_ver
  112. #undef linhad_hor
  113. #undef linhad_ver
  114.  
  115.     //mkline4 macros (redefining old and creating new linha... macros)
  116. #define linha_hor(y,xi,xf,color)\
  117.     mkline4(y,xi,xf,color,0) //draws a single horizontal line
  118. #define linha_ver(x,yi,yf,color)\
  119.     mkline4(x,yi,yf,color,1) //draws a single vertical line
  120. #define linhad_hor(y,xi,xf,color)\
  121.     mkline4(y,xi,xf,color,2) //draws a double horizontal line
  122. #define linhad_ver(x,yi,yf,color)\
  123.     mkline4(x,yi,yf,color,3) //draws a double horizontal line
  124. #define linhat_hor(y,xi,xf,color)\
  125.     mkline4(y,xi,xf,color,4) //draws a triple horizontal line
  126. #define linhat_ver(x,yi,yf,color)\
  127.     mkline4(x,yi,yf,color,5) //draws a triple horizontal line
  128. #define linhaq_hor(y,xi,xf,color)\
  129.     mkline4(y,xi,xf,color,6) //draws a quadruple horizontal line
  130. #define linhaq_ver(x,yi,yf,color)\
  131.     mkline4(x,yi,yf,color,7) //draws a quadruple horizontal line
  132.  
  133.   //program main function
  134. void main ()
  135.  {
  136.     int i=0,j=0,k=0;
  137.     int c0;
  138.  
  139.  //displays warning message
  140.     fillscr (' ',0x07);
  141.     crt_gotoxy(0,6);
  142.     crtwin_just=0;
  143.     printsj ("WARNING: If you are running this example from a MS-WINDOWS MS-DOS prompt and",0,0x07);
  144.     printsj ("you want to see everything be sure that the MS-DOS prompt is running in full",1,0x07);
  145.     printsj ("screen mode, because some functions in this example aren't effective in a",2,0x07);
  146.     printsj ("MSDOS prompt window.",3,0x07);
  147.     printsj ("To toggle a MS-WINDOWS MS-DOS prompt between full screen mode / window mode",4,0x07);
  148.     printsj ("type ALT-ENTER.",5,0x07);
  149.     pause ();
  150.     crtwin_just=1;
  151.  
  152.  //selects mkline4 font and updates crtframe_mat
  153.     initxmkline();
  154.  
  155.  //crtframe, crtframew and mkline4 macros examples
  156.     fillscr ('░',0x19);
  157.     prints ("* * * fillbar, crtframe and mkline4 example * * *",16,1,0x17);
  158.     prints ("Using macros moldura... and linha...",21,2,0x17);
  159.  
  160.     setcrtwin (2,5,18,13);
  161.     molduraw (0x1f);
  162.     fillbarw (' ',0x19);
  163.     pause ();
  164.  
  165.     setcrtwin (22,5,38,13);
  166.     molduradw (0x1f);
  167.     fillbarw (' ',0x19);
  168.     pause ();
  169.  
  170.     setcrtwin (42,5,58,13);
  171.     molduratw (0x1f);
  172.     fillbarw (' ',0x19);
  173.     pause ();
  174.  
  175.     setcrtwin (62,5,78,13);
  176.     molduraqw (0x1f);
  177.     fillbarw (' ',0x19);
  178.     pause ();
  179.  
  180.  
  181.     linha_hor  (9, 2,18,0x1e);
  182.     linhad_hor (9,22,38,0x1e);
  183.     linhat_hor (9,42,58,0x1e);
  184.     linhaq_hor (9,62,78,0x1e);
  185.     pause ();
  186.  
  187.     linha_ver  (10,5,13,0x1e);
  188.     linhad_ver (30,5,13,0x1e);
  189.     linhat_ver (50,5,13,0x1e);
  190.     linhaq_ver (70,5,13,0x1e);
  191.     pause ();
  192.  
  193.     prints ("- - - Hit any key to continue - - -",22,24,0x97);
  194.     pause ();
  195.  
  196. //crtframe and moldura... example
  197.  
  198.     fillscr ('░',0x19);
  199.     setcrtwin (-1,-1,80,25);
  200.     printsj ("* * * Example of frames draw by * * *",1,0x17);
  201.     printsj ("* * * crtframe with modified crtframe_mat * * *",2,0x17);
  202.     pause ();
  203.  
  204.     moldura (10,5,20,8,0x1f);
  205.     prints ("type = 0",11,9,0x17);
  206.     pause ();
  207.  
  208.     moldurad (50,5,60,8,0x1f);
  209.     prints ("type = 1",51,9,0x17);
  210.     pause ();
  211.  
  212.     moldurat (10,15,20,18,0x1f);
  213.     prints ("type = 2",11,19,0x17);
  214.     pause ();
  215.  
  216.     //Normally user defined character, but now quadruple outline frame
  217.     molduraq (50,15,60,18,0x1f);
  218.     prints ("type = 3",51,19,0x17);
  219.     pause ();
  220.  
  221.  //As any call to crtframe with "type" greater than 255 redefines crtframe_mat
  222.  //positions 24 through 31 (that are being used by quadruple outline). A call
  223.  //to crtframe with any value greater than 255 would destroy the quadruple
  224.  //outline, therefore the lines below have been disabled.
  225.  
  226.  /*
  227.     crtframe (37,15,47,18,0x1f,0x101);
  228.     //user defined character is redefined as'■'
  229.     prints ("type = 101h",37,19,0x17);
  230.     pause ();
  231.  
  232.     crtframe (63,15,73,18,0x1f,3);  //current user defined character='■');
  233.     prints ("type = 3",64,19,0x17);
  234.     pause ();
  235.  */
  236.  
  237. //crtframe and mkline4 example
  238.  
  239.  #define L0 1      //column initial position
  240.  #define L1 2      //row (line) initial position
  241.  #define L2 12     //each x side size
  242.  #define L3 4      //each y side size
  243.  #define L4 6      //x median
  244.  #define L5 2      //y median
  245.  #define L6 20     //smaller spacing in x
  246.  #define L7 6      //spacing in y
  247.  #define L8 0      //bigger spacing in x
  248.  #define CF 0x1e   //crtframe color
  249.  #define CL 0x1f   //mkline4 color
  250.  
  251.     fillscr ('░',0x19);
  252.     for (i=0;i<4;i++)
  253.      {
  254.         fillscr ('░',0x19);
  255.         prints ("* * * FRAME TYPES * * *",28,0,0x17);
  256.         for (j=0;j<4;j++)
  257.             for (k=0;k<4;k++)
  258.              {
  259.                 crtframe (L0+L6*k+L8*i,L1+L7*j,L0+L2+L6*k+L8*i,L1+L3+L7*j,CF,i);
  260.                 mkline4(L1+L5+L7*j,L0+L6*k+L8*i,L0+L2+L6*k+L8*i,CL,2*k);
  261.                 mkline4(L0+L4+L6*k+L8*i,L1+L7*j,L1+L3+L7*j,CL,2*j+1);
  262.              }
  263.         pause ();
  264.      }
  265.  
  266. //Example of drawing a interesting text box, with many divisions inside,
  267. //organized in a hierarchical way that resembles fractals.
  268.  
  269.     fillscr ('░',0x19);
  270.  
  271.     molduraq (8,0,72,24,0x1b);
  272.  
  273.     for (c0=12;c0<72;c0+=8)
  274.         fillbar('l',c0,1,c0,23,0x1c);
  275.  
  276.     for (c0=0;c0<4;c0++)